package com.nkzy.controller;

import com.nkzy.pojo.Category;
import com.nkzy.pojo.Result;
import com.nkzy.service.CategoryService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    //1增加分类、
    @PostMapping
    public Result add(@RequestBody @Validated Category category){
        categoryService.add(category);
        return Result.success();
    }
    //2.查询分类（所有）
    @GetMapping
    public Result list(){
        List<Category> cs=categoryService.list();
        return Result.success(cs);
    }
    //2.5查询单个分类
    @GetMapping("/detail")
    public Result detail(Integer id){
        Category c=categoryService.findById(id);
        return Result.success(c);
    }
    //3.修改分类
    @PutMapping
    public Result update(@RequestBody Category category){
        categoryService.update(category);

        return Result.success();
    }
    //4.删除分类
    @DeleteMapping
    public Result delete(Integer id){
        Category d=categoryService.deleteById(id);
        return Result.success(d);
    }
}


































































